package com.open.exam.sqlprovider;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 奶茶
 * Created by on 2017/11/22.
 */
public class ExamRoomMapperProvider {

    private static final Logger logger = LoggerFactory.getLogger(ExamRoomMapperProvider.class);

    public String findExamRoomListBySomeWhere(Map<String,Object> parameter){
        StringBuilder sb = new StringBuilder();
        String appId = (String) parameter.get("appId");
        String planId = (String) parameter.get("planId");
        String sceneId = (String) parameter.get("sceneId");
        String subjectId = (String) parameter.get("subjectId");

        sb.append("SELECT x.* FROM ExamRoom AS x JOIN ExamineeArrange AS y ON x.ExamRoomID = y.ExamRoomID AND x.AppID = y.AppID WHERE 1=1");
        if(appId != null && !("").equals(appId)){
            sb.append(" AND y.AppID = \'").append(appId).append("\'");
        }
        if(planId != null){
            sb.append(" AND y.ExamPlanInfoID = \'").append(planId).append("\' ");
        }
        if(sceneId != null){
            sb.append(" AND y.ExamSceneID = \'").append(sceneId).append("\' ");
        }
        if(subjectId != null){
            sb.append(" AND y.ExamSubjectID = \'").append(subjectId).append("\' ");
        }
        sb.append(" GROUP BY x.AppID, x.ExamSiteID, x.ExamRoomID");

        String sql = sb.toString();
        logger.info(sql);
        return sql;
    }

    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<>();
        map.put("appId","1");
        map.put("planId",66);
        map.put("sceneId",154);
        map.put("subjectId",246);

//        findExamRoomListBySomeWhere(map);
    }
}
